'''
Created on 13.06.2012
Prototype that draws a sequence chart.

First prototype:
+-------+   +-----+
| Alice |   | Bob |
+-------+   +-----+
    |   Bla    |
    +--------->+
    |  Ohja    |
    +<---------+
    |          |
+-------+   +-----+
| Alice |   | Bob |
+-------+   +-----+

@author: dominik
'''
import Image, ImageDraw, ImageFont
import prot01SequenceTheme
from prototypeRenderer import PrototypeRenderer
"""
def actors_line(actors):
    
    global actor_image
    global actor_center
    x = 0
    actor_images = []
    for actor in actors:
        image = actor_image(actor)
        actor_center[actor] = x + image.size[0] / 2
        x += image.size[0] + ACTOR_MARGIN_X
        actor_images.append(image)
    x -= ACTOR_MARGIN_X
    image = Image.new("RGBA", (x, actor_images[0].size[1]), "white")
    x = 0
    for actor_image in actor_images:
        image.paste(actor_image, (x, 0))
        x += ACTOR_MARGIN_X
        x += actor_image.size[0]
    return image
def draw_action(action):
    global actor_center
    left = actor_center[action[0]]
    right = actor_center[action[2]]
    if left > right:
        left, right = right, left
    
    width = right - left
    height = font_text.getsize(action[1])[1]
    
    image = Image.new("RGBA", (width, height+1), "white")
    draw = ImageDraw.Draw(image)
    draw.line(((0,height),(width, height)), fill="black")
    draw.text((((width) - font_text.getsize(action[1])[0]) / 2, 0), action[1], font=font_text, fill="black")
    return image

"""
def main():
    test_actors = ("Alice", "Bob")
    test_actions = [
        ("Alice", "Bla", "Bob"),
        ("Bob", "Ohja", "Alice")
    ]
    
    rend = PrototypeRenderer(test_actors, test_actions, prot01SequenceTheme)
    image = rend.get_image()
    image.show()

#    image = Image.new("RGBA", (width, height), "white")
#
#    image.paste(actorsLine, (IMAGE_MARGIN, IMAGE_MARGIN))
#    y = image.size[1] - IMAGE_MARGIN - actorsLine.size[1]
#    image.paste(actorsLine, (IMAGE_MARGIN, y))
#    
#    for height, img_and_action in action_images.items():
#        image.paste(img_and_action[0], (actor_center[img_and_action[1][0]], height))
#    
#    image.show()

if __name__ == '__main__':
    main()